// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_PlatformManager = require("./AL_GAME_HUA_PlatformManager");
// var AL_GAME_HUA_MissionConfig = require("./AL_GAME_HUA_MissionConfig");
// var AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
// var AL_GAME_HUA_PlayerInfo = require("./AL_GAME_HUA_PlayerInfo");
// var _ = cc._decorator;
// var P = _.ccclass;
// var g = _.property;
// var y =
//     (_.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.node_title_win = null;
//             t.node_title_fail = null;
//             t.label_star_count = null;
//             t.label_progress = null;
//             t.progress_bar = null;
//             t.box = null;
//             t.box_Materials = [];
//             t.geted_node = null;
//             t.options = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.zhixing_chushihua_chuli = function (e) {
//             this.options = e;
//             this.label_star_count.string = "+" + this.options.label_star_count.toString();
//             this.label_progress.string = e.complete ? "2/2" : AL_GAME_HUA_Instance.Instance.ChallengeLevel - 1 + "/2";
//             this.progress_bar.progress = e.complete ? 1 : (AL_GAME_HUA_Instance.Instance.ChallengeLevel - 1) / 2;
//             this.node_title_win.active = e.complete;
//             this.node_title_fail.active = !e.complete;
//             this.box.setMaterial(
//                 0,
//                 this.box_Materials[AL_GAME_HUA_GameData.GameData.getInstance().huoqu_jinri_tiaozhan() ? 1 : 0]
//             );
//             this.geted_node.active = AL_GAME_HUA_GameData.GameData.getInstance().huoqu_jinri_tiaozhan();
//             AL_GAME_HUA_GameData.GameData.getInstance().tianjia_xingxing_shuliang(this.options.label_star_count);
//             this.baocun_paiming();
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: !0
//             });
//             AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
//                 AL_GAME_HUA_MissionConfig.MissionType.CHALLENGE
//             );
//             this.jiancha_jiangli();
//         };
//         t.prototype.baocun_paiming = function () {
//             if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
//                 ailin_sdk_manager.shezhiPaihangbangShuju("score", AL_GAME_HUA_GameData.GameData.getInstance().huoqu_xingxing_shuliang());
//             }
//             "tt" == ailin_sdk_manager.getSysPlatformName()
//                 ? AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.setImRankData({
//                       value: AL_GAME_HUA_GameData.GameData.getInstance().huoqu_xingxing_shuliang()
//                   })
//                 : "wx" == ailin_sdk_manager.getSysPlatformName() &&
//                   ailin_sdk_manager.tijiaoPaihangbangFenshu &&
//                   ailin_sdk_manager.tijiaoPaihangbangFenshu({
//                       data: {
//                           score: AL_GAME_HUA_GameData.GameData.getInstance().huoqu_xingxing_shuliang()
//                       }
//                   });
//         };
//         t.prototype.jiancha_jiangli = function () {
//             var e = this;
//             return new Promise(function (t) {
//                 if (e.options.complete && !AL_GAME_HUA_GameData.GameData.getInstance().huoqu_jinri_tiaozhan()) {
//                     AL_GAME_HUA_PlayerInfo.PlayerInfo.getInstance().zengjia_dengji();
//                     AL_GAME_HUA_GameData.GameData.getInstance().shezhi_jinri_tiaozhan(!0);
//                     e.box.setMaterial(0, e.box_Materials[1]);
//                     e.node.opacity = 0;
//                     return void AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
//                         type: AL_GAME_HUA_Define.Define.AwardType.CHALLENGE,
//                         chuli_lingqu: function () {
//                             AL_GAME_HUA_Instance.Instance.jinru_zhujiemian();
//                             t();
//                         }
//                     });
//                 }
//                 t();
//             });
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             switch (t) {
//                 case "back":
//                     AL_GAME_HUA_Instance.Instance.jinru_zhujiemian();
//                     break;
//                 case "continue":
//                     AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(function () {
//                         AL_GAME_HUA_Instance.Instance.ChallengeLevel = 1;
//                         AL_GAME_HUA_Instance.Instance.qianwang_youxi();
//                     });
//             }
//         };
//         __decorate([g(cc.Node)], t.prototype, "node_title_win", void 0);
//         __decorate([g(cc.Node)], t.prototype, "node_title_fail", void 0);
//         __decorate([g(cc.Label)], t.prototype, "label_star_count", void 0);
//         __decorate([g(cc.Label)], t.prototype, "label_progress", void 0);
//         __decorate([g(cc.ProgressBar)], t.prototype, "progress_bar", void 0);
//         __decorate([g(cc.Sprite)], t.prototype, "box", void 0);
//         __decorate([g([cc.Material])], t.prototype, "box_Materials", void 0);
//         __decorate([g(cc.Node)], t.prototype, "geted_node", void 0);
//         return __decorate([P], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = y;


// // 引入相关模块
// var addPrefabModule = require("./AL_GAME_HUA_AddPrefab");
// var instanceModule = require("./AL_GAME_HUA_Instance");
// var defineModule = require("./AL_GAME_HUA_Define");
// var popupSelfModule = require("./AL_GAME_HUA_PopupSelf");
// var platformManagerModule = require("./AL_GAME_HUA_PlatformManager");
// var missionConfigModule = require("./AL_GAME_HUA_MissionConfig");
// var gameDataModule = require("./AL_GAME_HUA_GameData");
// var playerInfoModule = require("./AL_GAME_HUA_PlayerInfo");

// var decorator = cc._decorator;
// var classDecorator = decorator.ccclass;
// var propertyDecorator = decorator.property;

// /**
//  * ChallengePopup 类
//  * 该类负责处理挑战结果的显示和逻辑处理。
//  */
// var ChallengePopup =
//     (function (PopupSuperClass) {
//         // 继承PopupSuperClass
//         function ChallengePopup() {
//             // 调用父类构造函数
//             var self = (null !== PopupSuperClass && PopupSuperClass.apply(this, arguments)) || this;

//             // 定义类属性
//             self.node_title_win = null;
//             self.node_title_fail = null;
//             self.label_star_count = null;
//             self.label_progress = null;
//             self.progress_bar = null;
//             self.box = null;
//             self.box_Materials = [];
//             self.geted_node = null;
//             self.options = null;
//             return self;
//         }

//         // 继承关系
//         __extends(ChallengePopup, PopupSuperClass);

//         /**
//          * 初始化方法
//          * 初始化方法，用于设置挑战结果显示。
//          * @param options - 初始化选项
//          */
//         ChallengePopup.prototype.zhixing_chushihua_chuli = function (options) {
//             this.options = options;
//             this.label_star_count.string = "+" + this.options.label_star_count.toString();
//             var challengeLevel = instanceModule.Instance.ChallengeLevel;
//             this.label_progress.string = options.complete ? "2/2" : (challengeLevel - 1) + "/2";
//             this.progress_bar.progress = options.complete ? 1 : (challengeLevel - 1) / 2;
//             this.node_title_win.active = options.complete;
//             this.node_title_fail.active = !options.complete;
//             var boxMaterialIndex = gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan() ? 1 : 0;
//             this.box.setMaterial(0, this.box_Materials[boxMaterialIndex]);
//             this.geted_node.active = gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan();
//             gameDataModule.GameData.getInstance().tianjia_xingxing_shuliang(this.options.label_star_count);
//             this.baocun_paiming();
//             instanceModule.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: true
//             });
//             missionConfigModule.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
//                 missionConfigModule.MissionType.CHALLENGE
//             );
//             this.jiancha_jiangli();
//         };

//         /**
//          * 保存排名
//          * 保存玩家的当前分数到排行榜。
//          */
//         ChallengePopup.prototype.baocun_paiming = function () {
//             var gameDataInstance = gameDataModule.GameData.getInstance();
//             var score = gameDataInstance.huoqu_xingxing_shuliang();
//             if (cc.sys.isNative && cc.sys.os === cc.sys.OS_IOS) {
//                 ailin_sdk_manager.shezhiPaihangbangShuju("score", score);
//             }

//             var platformName = ailin_sdk_manager.getSysPlatformName();
//             if ("tt" == platformName) {
//                 platformManagerModule.PlatformManager.getInstance().tt.setImRankData({ 
//                     value: score
//                 });
//             } else if ("wx" == platformName && ailin_sdk_manager.tijiaoPaihangbangFenshu) {
//                 ailin_sdk_manager.tijiaoPaihangbangFenshu({
//                     data: {
//                         score: score
//                     }
//                 });
//             }
//         };

//         /**
//          * 检查奖励
//          * 检查并处理挑战完成后的奖励发放。
//          * @returns {Promise}
//          */
//         ChallengePopup.prototype.jiancha_jiangli = function () {
//             var self = this;
//             return new Promise(function (resolve) {
//                 if (self.options.complete && !gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan()) {
//                     playerInfoModule.PlayerInfo.getInstance().zengjia_dengji();
//                     gameDataModule.GameData.getInstance().shezhi_jinri_tiaozhan(true);
//                     self.box.setMaterial(0, self.box_Materials[1]);
//                     self.node.opacity = 0;
//                     return void addPrefabModule.AddPrefab.create_award({
//                         type: defineModule.Define.AwardType.CHALLENGE,
//                         chuli_lingqu: function () {
//                             instanceModule.Instance.jinru_zhujiemian();
//                             resolve();
//                         }
//                     });
//                 }
//                 resolve();
//             });
//         };

//         /**
//          * 按钮回调处理
//          * 根据按钮标识处理不同的按钮行为。
//          * @param event - 事件对象
//          * @param action - 按钮行为标识
//          */
//         ChallengePopup.prototype.handle_button_callback = function (event, action) {
//             switch (action) {
//                 case "back":
//                     instanceModule.Instance.jinru_zhujiemian();
//                     break;
//                 case "continue":
//                     instanceModule.Instance.jiancha_tili_shifou_zugou(function () {
//                         instanceModule.Instance.ChallengeLevel = 1;
//                         instanceModule.Instance.qianwang_youxi();
//                     });
//                     break;
//             }
//         };

//         // 类属性装饰
//         __decorate([propertyDecorator(cc.Node)], ChallengePopup.prototype, "node_title_win", void 0);
//         __decorate([propertyDecorator(cc.Node)], ChallengePopup.prototype, "node_title_fail", void 0);
//         __decorate([propertyDecorator(cc.Label)], ChallengePopup.prototype, "label_star_count", void 0);
//         __decorate([propertyDecorator(cc.Label)], ChallengePopup.prototype, "label_progress", void 0);
//         __decorate([propertyDecorator(cc.ProgressBar)], ChallengePopup.prototype, "progress_bar", void 0);
//         __decorate([propertyDecorator(cc.Sprite)], ChallengePopup.prototype, "box", void 0);
//         __decorate([propertyDecorator([cc.Material])], ChallengePopup.prototype, "box_Materials", void 0);
//         __decorate([propertyDecorator(cc.Node)], ChallengePopup.prototype, "geted_node", void 0);

//         return __decorate([classDecorator], ChallengePopup);
//     })(popupSelfModule.default);

// exports.default = ChallengePopup;



// 引入相关模块
const addPrefabModule = require("./AL_GAME_HUA_AddPrefab");
const instanceModule = require("./AL_GAME_HUA_Instance");
const defineModule = require("./AL_GAME_HUA_Define");
const popupSelfModule = require("./AL_GAME_HUA_PopupSelf");
const platformManagerModule = require("./AL_GAME_HUA_PlatformManager");
const missionConfigModule = require("./AL_GAME_HUA_MissionConfig");
const gameDataModule = require("./AL_GAME_HUA_GameData");
const playerInfoModule = require("./AL_GAME_HUA_PlayerInfo");

// 引入 Cocos Creator 的装饰器模块
const { ccclass, property } = cc._decorator;

/**
 * ChallengePopup 类
 * 负责处理挑战结果的显示和相关逻辑。
 */
@ccclass
class ChallengePopup extends popupSelfModule.default {
    @property(cc.Node)
    node_title_win = null;

    @property(cc.Node)
    node_title_fail = null;

    @property(cc.Label)
    label_star_count = null;

    @property(cc.Label)
    label_progress = null;

    @property(cc.ProgressBar)
    progress_bar = null;

    @property(cc.Sprite)
    box = null;

    @property([cc.Material])
    box_Materials = [];

    @property(cc.Node)
    geted_node = null;

    /**
     * 初始化方法
     * 用于设置挑战结果的显示。
     * @param {Object} options - 初始化选项
     */
    zhixing_chushihua_chuli(options) {
        this.options = options;
        this.label_star_count.string = `+${this.options.label_star_count}`;
        const challengeLevel = instanceModule.Instance.ChallengeLevel;

        // 设置进度标签和进度条
        this.label_progress.string = options.complete ? "2/2" : `${challengeLevel - 1}/2`;
        this.progress_bar.progress = options.complete ? 1 : (challengeLevel - 1) / 2;

        // 设置标题的显示状态
        this.node_title_win.active = options.complete;
        this.node_title_fail.active = !options.complete;

        // 设置宝箱材质
        const boxMaterialIndex = gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan() ? 1 : 0;
        this.box.setMaterial(0, this.box_Materials[boxMaterialIndex]);

        // 设置已领取节点的显示状态
        this.geted_node.active = gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan();

        // 增加星星数量
        gameDataModule.GameData.getInstance().tianjia_xingxing_shuliang(this.options.label_star_count);

        // 保存排名
        this.baocun_paiming();

        // 显示顶部条
        instanceModule.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showAll: true,
        });

        // 增加任务进度
        missionConfigModule.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
            missionConfigModule.MissionType.CHALLENGE
        );

        // 检查奖励
        this.jiancha_jiangli();
    }

    /**
     * 保存排名
     * 保存玩家的分数到排行榜。
     */
    baocun_paiming() {
        const gameDataInstance = gameDataModule.GameData.getInstance();
        const score = gameDataInstance.huoqu_xingxing_shuliang();

        // 针对iOS平台调用SDK保存排名
        if (cc.sys.isNative && cc.sys.os === cc.sys.OS_IOS) {
            ailin_sdk_manager.shezhiPaihangbangShuju("score", score);
        }

        // 针对不同平台的排名处理逻辑
        const platformName = ailin_sdk_manager.getSysPlatformName();
        if (platformName === "tt") {
            platformManagerModule.PlatformManager.getInstance().tt.setImRankData({ value: score });
        } else if (platformName === "wx" && ailin_sdk_manager.tijiaoPaihangbangFenshu) {
            ailin_sdk_manager.tijiaoPaihangbangFenshu({
                data: { score: score },
            });
        }
    }

    /**
     * 检查奖励
     * 检查并处理挑战完成后的奖励发放。
     * @returns {Promise<void>}
     */
    async jiancha_jiangli() {
        if (this.options.complete && !gameDataModule.GameData.getInstance().huoqu_jinri_tiaozhan()) {
            playerInfoModule.PlayerInfo.getInstance().zengjia_dengji();
            gameDataModule.GameData.getInstance().shezhi_jinri_tiaozhan(true);
            this.box.setMaterial(0, this.box_Materials[1]);
            this.node.opacity = 0;

            await addPrefabModule.AddPrefab.create_award({
                type: defineModule.Define.AwardType.CHALLENGE,
                chuli_lingqu: () => {
                    instanceModule.Instance.jinru_zhujiemian();
                },
            });
        }
    }

    /**
     * 按钮回调处理
     * 根据按钮标识处理不同的按钮行为。
     * @param {Event} event - 事件对象
     * @param {string} action - 按钮行为标识
     */
    handle_button_callback(event, action) {
        switch (action) {
            case "back":
                instanceModule.Instance.jinru_zhujiemian();
                break;
            case "continue":
                instanceModule.Instance.jiancha_tili_shifou_zugou(() => {
                    instanceModule.Instance.ChallengeLevel = 1;
                    instanceModule.Instance.qianwang_youxi();
                });
                break;
        }
    }
}

module.exports = ChallengePopup;
